package cn.netjava.robo3d.event;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.netjava.robo3d.TankInformation;
import cn.netjava.robo3d.device.Bullet;

public class HitByBulletEvent {
	private List<TankInformation> allothertanksinfo;       //引用所有其它坦克
	private TankInformation info;
	private Map bulletsmap;                  //打在我身上的子弹与坦克的对应
	private int totalbullets=0;                    //打在我身上的所有子弹

	public HitByBulletEvent(TankInformation info,List<TankInformation> allothertanksinfo){
		this.info=info;
		this.allothertanksinfo=allothertanksinfo;
		bulletsmap=new HashMap();
	}

	public Map getBulletsmap() {
		return bulletsmap;
	}

	public int getTotalbullets() {
		return totalbullets;
	}

	public boolean ishappen(){
		boolean happen=false;

		//把每一辆坦克的所有已激活子弹寻找一遍
		for(int i=0;i<allothertanksinfo.size();i++){
			TankInformation temptank=allothertanksinfo.get(i);
			  int onetankcount=0;              //一个坦克打在我身上的子弹

			 for(int j=0;j<temptank.getBullets().size();j++){
				    Bullet tempbullet=(Bullet)temptank.getBullets().get(j);
				    //激活子弹离我很近
				    if(tempbullet.islive()&&tempbullet.getCurrentloc().distance(info.getLocaltranslation())<2f){
				    	//中弹
				    	onetankcount++;
				    	totalbullets++;
				    	//对方加分
				    	temptank.setScore(temptank.getScore()+2);
				    	//对方的这颗子弹先停止，然后爆炸
				    	tempbullet.bomb();

				    	happen=true;
				    }
			 }
			  if(onetankcount>0){
			    bulletsmap.put(temptank.getName(), onetankcount);
			  }
		}

		return happen;
	}


}
